import  {LGXEnums}  from '../../sysenum.js'
import UtilFuncs from '../../tools/utilfuncs.js'
var utilfuncs = UtilFuncs.UtilFuncs;

var oldfulltype = function (id) {
    var strID = id.toString(16);
    var strFulltype = strID.substr(0, 7);
    var type1 = parseInt(strFulltype, 16);
    var type = type1 & 0xffffffff;
    return type;
}

class AbsStruct {
    constructor() {
        this.type = 0;//图形类型，规则：0x02010101
        this.superID = "";//所属容器对象rid
        this.modifyType = LGXEnums.ModifyType.NoneType_mod;

        this.gid = 0;
        this.rid = "";
        this.scope_left = 0;
        this.scope_top = 0;
        this.scope_right = 0;
        this.scope_bottom = 0;
        this.sSymbolName = 0;
        this.xlink = "";
        this.inLayIdx = 0;//在逻辑图层中的顺序，默认为-1，表示放在队尾
        this.layerName = "lay0";
        this.angle = 0;//角度值
        this.mirrorDisFlag = 0;
        this.mouldName = "";//所属图形组名称
        this.remarkInfo = "";//备注信息，图形内部只做存取，具体业务应用由应用层自己决定
        this.pos = null;
        this.state = 0;
        this.color = 0;
        this.m_nUseful = 0;
        this.m_nNewAdd = 0;
        this.exSetNewFlag = false;//由外部应用通过结构体对象来生成图形对象的标识，如文本编辑,不持久化
        this.refSymbolUUID = '';//引用的图符的UUID
        this.superSymType = 0;
    }

    toJson() { }
    fromJson(obj) { }
    cloneCopy() { }
    translate(tx,ty){}
    translateSubInfo(tx,ty){}

    setScopeRect(minx, miny, maxx, maxy) {
        this.scope_left = minx;
        this.scope_bottom = miny;
        this.scope_right = maxx;
        this.scope_top = maxy;
    }

    getgid() {
        return this.gid;
    }

    setgid(gid) {
        this.gid = gid;
    }

    setPos(srcPos) {
        if (srcPos && this.pos)
            this.pos.clone(srcPos);
    }

    getPos() {
        return this.pos;
    }

    getAngle() {
        return this.angle;
    }

    setAngle(v) {
        this.angle = v;
    }

    offsetPos(tx, ty) {
        this.pos.offset(tx, ty);
    }

    commonPropToJson(obj) {
        obj["type"] = this.type;
        obj["gid"] = this.gid;
        obj["rid"] = this.rid;

        obj["superID"] = this.superID;
        obj["state"] = this.state;

        obj["scope_left"] = this.scope_left;
        obj["scope_top"] = this.scope_top;
        obj["scope_right"] = this.scope_right;
        obj["scope_bottom"] = this.scope_bottom;

        obj["layerName"] = this.layerName;
        obj["xlink"] = this.xlink;

        obj["angle"] = this.angle;
        obj["conn2DevResID"] = this.conn2DevResID;
        obj["mirrorDisFlag"] = this.mirrorDisFlag;
        obj["mouldName"] = this.mouldName;
        obj["remarkInfo"] = this.remarkInfo;
        obj["inLayIdx"] = this.inLayIdx;
        obj["sSymbolName"] = this.sSymbolName;
        obj["color"] = this.color;
        obj["m_nUseful"] = this.m_nUseful;
        obj["m_nNewAdd"] = this.m_nNewAdd;
        obj['refSymbolUUID'] = this.refSymbolUUID;
        obj['superSymType'] = this.superSymType;
    }

    commonPropFromJson(obj) {
        var tmp = obj["gid"];
        if (tmp != null) {
            this.gid = parseInt(tmp);
        }
        else {
            tmp = obj["graphID"];
            this.gid = 0;
        }

        tmp = obj["type"];
        if (tmp != null) {
            this.type = parseInt(tmp);
        }
        else {
            tmp = obj["graphID"];
            var devFullType = oldfulltype(tmp);
            this.type = parseInt(devFullType);
        }

        this.state = obj["state"];
        this.rid = obj["rid"];
        if (this.rid == null) {
            this.rid = "";
        }
        this.superID = obj["superID"];

        this.scope_left = obj["scope_left"];
        this.scope_top = obj["scope_top"];
        this.scope_right = obj["scope_right"];
        this.scope_bottom = obj["scope_bottom"];

        this.layerName = obj["layerName"];
        if (this.layerName == null) {
            this.layerName = obj["logicLayerName"];
        }
        this.xlink = obj["xlink"];
        if (this.xlink == null) {
            this.xlink = obj["connectGraph"];
        }

        this.angle = obj["angle"];
        if (this.angle == null) {
            this.angle = obj["angleDegree"];
        }

        this.mirrorDisFlag = obj["mirrorDisFlag"];
        this.mouldName = obj["mouldName"];
        this.remarkInfo = obj["remarkInfo"];
        this.inLayIdx = obj["inLayIdx"];
        if (this.inLayIdx < 1) {
            this.inLayIdx = -1;
        }
        this.color = obj["color"];
        this.m_nUseful = obj["m_nUseful"];
        this.m_nNewAdd = obj["m_nNewAdd"];
        this.refSymbolUUID = obj['refSymbolUUID'];
        this.superSymType = obj['superSymType'];
    }

    compare(pOther) {
        var sameflag = false;
        if (this.type == pOther.type) {
            sameflag = true;
        }

        if (!sameflag) {
            return false;
        }
        sameflag = false;
        if (pOther.gid == this.gid
            && pOther.rid == this.rid
            && pOther.xlink == this.xlink
            && pOther.layerName == this.layerName
            && pOther.angle == this.angle
            && pOther.mouldName == this.mouldName) {
            sameflag = true;
        }
        return sameflag;
    }

    cloneBaseProp(pOther){
        pOther.type = this.type;
        pOther.superID = this.superID;
        pOther.modifyType = this.modifyType;
        pOther.gid = this.gid;
        pOther.rid = this.rid;
        pOther.scope_left = this.scope_left;
        pOther.scope_top = this.scope_top;
        pOther.scope_right = this.scope_right;
        pOther.scope_bottom = this.scope_bottom;
        pOther.sSymbolName = this.sSymbolName;
        pOther.xlink = this.xlink;
        pOther.inLayIdx = this.inLayIdx;
        pOther.layerName = this.layerName;
        pOther.angle = this.angle;
        pOther.mirrorDisFlag = this.mirrorDisFlag;
        pOther.mouldName = this.mouldName;
        pOther.remarkInfo = this.remarkInfo;
        pOther.state = this.state;
        pOther.color = this.color;
        pOther.setPos(this.getPos());
        pOther.refSymbolUUID = this.refSymbolUUID;
        pOther.superSymType = this.superSymType;
    }

}

export default { AbsStruct }